<!doctype html>
{% extends "base.html" %}
{% block title %}定时调度{% endblock title %}

{% block page2_show %}show{% endblock page2_show %}
{% block page2.4_active %}active{% endblock page2.4_active %}

{% block main_content %}
<div class="row">
{% for host,crons in cronsDict.items %}
<div class="col-12 col-lg-6">
    <div class="card">
        <div class="card-header">
            <h5 class="card-title">{{ host }} 
                <a href="/refreshCron" class="btn btn-outline-info">立即更新</a>
            </h5>
            <ul class="nav nav-tabs card-header-tabs pull-right" role="tablist">
                {% for user,data in crons.items %}
                    <li class="nav-item">
                        <a class="nav-link {{ data.active }}" data-toggle="tab" href="#tab_{{ host }}_{{ user }}">{{ user }}</a>
                    </li>
                {% endfor %}
            </ul>
        </div>
        <div class="card-body">
            <div class="tab-content">
            {% for user,data in crons.items %}
                <div class="tab-pane fade {{ data.show }}" id="tab_{{ host }}_{{ user }}" role="tabpanel">
                    {% for cron in data.data %}
                        <ul class="list-group list-group-flush">
    						<li class="list-group-item">No.{{ forloop.counter }} ：{{ cron }}
                            <a href="" data-toggle="modal" data-target="#del_{{ host }}_{{ user }}_{{ forloop.counter }}"><i class="fe fe-trash float-right"></i></a>
                            <a href="" data-toggle="modal" data-target="#edit_{{ host }}_{{ user }}_{{ forloop.counter }}"><i class="fe fe-edit-3 float-right"></i></a>
                            {% if forloop.counter == 1 %}
                                <a href="" data-toggle="modal" data-target="#add_{{ host }}_{{ user }}"><i class="fe fe-plus-circle float-right"></i></a>
                            {% endif %}
                            </li>
                            {% comment %} 删除Cron的表单 {% endcomment %}
                            <div class="modal fade" id="del_{{ host }}_{{ user }}_{{ forloop.counter }}" tabindex="-1" role="dialog" aria-hidden="true">
								<div class="modal-dialog modal-dialog-centered" role="document">
									<div class="modal-content">
										<div class="modal-header">
											<h1 class="modal-title">是否删除 No.{{ forloop.counter }}</h1>
											<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							                    <span aria-hidden="true">&times;</span>
							                  </button>
										</div>
                                        <form method="post" action="/CronDel">
										<div class="modal-body m-3">
                                            <div class="form-group row">
                                                <label class="col-form-label col-sm-4 text-sm-right">ID</label>
                                                <div class="col-sm-8">
                                                    <input type="number" name="id" class="form-control" readonly="readonly" value="{{ forloop.counter }}">
                                                </div>
                                            </div>
                                            <div class="form-group row">
                                                <label class="col-form-label col-sm-4 text-sm-right">所属主机</label>
                                                <div class="col-sm-8">
                                                    <input type="text" name="hostname" value="{{ host }}" readonly="readonly" class="form-control">
                                                </div>
                                            </div>
                                            <div class="form-group row">
                                                <label class="col-form-label col-sm-4 text-sm-right">所属用户</label>
                                                <div class="col-sm-8">
                                                    <input type="text" name="username" value="{{ user }}" readonly="readonly" class="form-control">
                                                </div>
                                            </div>
											<p class="mb-0">删除后无法恢复，请慎重，点击 弹窗外/X按钮/取消按钮 可取消</p>
										</div>
										<div class="modal-footer">
											<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
											<button type="submit" class="btn btn-danger">删除</button>
										</div>
                                        </form>
									</div>
								</div>
							</div>
                            {% comment %} 修改Cron的表单 {% endcomment %}
                            <div class="modal fade" id="edit_{{ host }}_{{ user }}_{{ forloop.counter }}" tabindex="-1" role="dialog" aria-hidden="true">
								<div class="modal-dialog modal-dialog-centered" role="document">
									<div class="modal-content">
										<div class="modal-header">
											<h1 class="modal-title">修改 No.{{ forloop.counter }}</h1>
											<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							                    <span aria-hidden="true">&times;</span>
							                  </button>
										</div>
                                        <form method="post" action="/CronEdit">
										<div class="modal-body m-3">
                                            <div class="form-group row">
                                                <label class="col-form-label col-sm-4 text-sm-right">ID</label>
                                                <div class="col-sm-8">
                                                    <input type="number" name="id" class="form-control" readonly="readonly" value="{{ forloop.counter }}">
                                                </div>
                                            </div>
                                            <div class="form-group row">
                                                <label class="col-form-label col-sm-4 text-sm-right">所属主机</label>
                                                <div class="col-sm-8">
                                                    <input type="text" name="hostname" value="{{ host }}" readonly="readonly" class="form-control">
                                                </div>
                                            </div>
                                            <div class="form-group row">
                                                <label class="col-form-label col-sm-4 text-sm-right">所属用户</label>
                                                <div class="col-sm-8">
                                                    <input type="text" name="username" value="{{ user }}" readonly="readonly" class="form-control">
                                                </div>
                                            </div>
                                            <div class="form-group row">
                                                <label class="col-form-label col-sm-4 text-sm-right">修改后：</label>
                                                <div class="col-sm-8">
                                                    <input type="text" name="context" required="" class="form-control">
                                                </div>
                                            </div>
										</div>
										<div class="modal-footer">
											<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
											<button type="submit" class="btn btn-primary">修改</button>
										</div>
                                        </form>
									</div>
								</div>
							</div>
                            {% if forloop.counter == 1 %}
                                {% comment %} 新增Cron的表单 {% endcomment %}
                                <div class="modal fade" id="add_{{ host }}_{{ user }}" tabindex="-1" role="dialog" aria-hidden="true">
    								<div class="modal-dialog modal-dialog-centered" role="document">
    									<div class="modal-content">
    										<div class="modal-header">
    											<h1 class="modal-title">新增Cron</h1>
    											<button type="button" class="close" data-dismiss="modal" aria-label="Close">
    							                    <span aria-hidden="true">&times;</span>
    							                  </button>
    										</div>
                                            <form method="post" action="/CronAdd">
    										<div class="modal-body m-3">
                                                <div class="form-group row">
                                                    <label class="col-form-label col-sm-4 text-sm-right">所属主机</label>
                                                    <div class="col-sm-8">
                                                        <input type="text" name="hostname" value="{{ host }}" readonly="readonly" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="form-group row">
                                                    <label class="col-form-label col-sm-4 text-sm-right">所属用户</label>
                                                    <div class="col-sm-8">
                                                        <input type="text" name="username" value="{{ user }}" readonly="readonly" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="form-group row">
                                                    <label class="col-form-label col-sm-4 text-sm-right">新增Cron：</label>
                                                    <div class="col-sm-8">
                                                        <input type="text" name="context" required="" class="form-control">
                                                    </div>
                                                </div>
    										</div>
    										<div class="modal-footer">
    											<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
    											<button type="submit" class="btn btn-primary">确定</button>
    										</div>
                                            </form>
    									</div>
    								</div>
    							</div>
                            {% endif %}
    					</ul>
                    {% endfor %}
                </div>
            {% endfor %}
            </div>
        </div>
    </div>
</div>
{% endfor %}
</div>
{% endblock main_content %}

{% block script %}
{% endblock script %}